<template>
	<view>
		<view>
			<u-subsection :list="subsectionList" active-color="#2979ff" bg-color="#eeeeef" button-color="#ffffff"
				:current="current" :animation="true" @change="change"></u-subsection>
		</view>
		<view style="padding: 30rpx;background-color: white;" v-if="orders">
			<u-form :model="form" ref="uForm" label-width="200">
				<u-form-item label="取车点简称" prop="location_name">
					<u-input v-model="form.location_name" />
				</u-form-item>
				<u-form-item label="取车点地址" prop="location_address">
					<u-input v-model="form.location_address" />
				</u-form-item>
				<u-form-item label="取车时间" prop="takereturen_date">
					<u-input :disabled="true" v-model="form.takereturen_date"  @click="showDatepicker=true" />
					<u-picker v-model="showDatepicker" :params="params" mode="time" @confirm="confirm" :default-time="defaultTime"></u-picker>
				</u-form-item>
				<u-form-item label="取车方式">
					<u-radio-group v-model="form.action_type">
						<u-radio v-for="(item, index) in [{value:1,name:'上门送车'},{value:2,name:'客户自取'}]" :key="index"
							:name="item.value">
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item>
					<u-button @click="submit" type="primary">提交修改</u-button>
				</u-form-item>
			</u-form>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				defaultTime:'',
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true
				},
				showDatepicker: false,
				current: 0,
				subsectionList: [{
					name: '取车信息'
				}, {
					name: '还车信息'
				}],
				orders: null,
				form: {
					location_name: '',
					location_address: '',
					takereturen_date: '',
					action_type: ''
				},
				rules: {
					location_name: [{
						required: true,
						message: '请输入取车地点',
						trigger: ['blur', 'change']
					}],
					location_address: [{
						required: true,
						message: '请输入取车地址',
						trigger: ['blur', 'change']
					}],
					takereturen_date: [{
						required: true,
						message: '请选择取车时间',
						trigger: ['blur', 'change']
					}],
					action_type: [{
						required: true,
						message: '请选择取车方式',
						trigger: ['blur', 'change']
					}],

				}
			}
		},
		onLoad(options) {
			if (options.data) {
				this.orders = JSON.parse(decodeURIComponent(options.data));
				console.log(this.orders);
				this.change(0);
			}
		},
		methods: {
			confirm(e){
				var date=e.year+'-'+e.month+'-'+e.day+' '+e.hour+':'+e.minute;
				this.form.takereturen_date=date;
				console.log(date);
			},
			change(e) {
				if (e == 0) {
					this.form = this.orders.takeReturn3 ? this.orders.takeReturn3 : this.orders.takeReturn1;
					this.defaultTime=this.orders.take_date;
				} else {
					this.form = this.orders.takeReturn4 ? this.orders.takeReturn4 : this.orders.takeReturn2;
					this.defaultTime=this.orders.return_date;
				}
			},
			submit() {
				var that = this;

				that.$http.post('/orders/updateTakeReturnDatetime', this.form, (res) => {
					if (res.data.success) {
						console.log(that.$refs.uToast);
						that.$refs.uToast.show({
							title: '修改成功',
							type: "success"
						});
						uni.$emit("getOrdersInfo", that.data);
						uni.navigateBack();
					} else {
						that.$refs.myModal.show('登录失败', res.data.result.message);
					}
				});
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style>

</style>